import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;


public class MyObject implements MySaidaListener{
	
	private String nome;
	private ObjectOutputStream saida;
	
	public MyObject(ObjectOutputStream s, String nomeUsuario) throws UnknownHostException, IOException {
		// TODO Auto-generated constructor stub
		this.saida = s;
		this.nome = nomeUsuario;
	}
	
	public String getNome() {
		return nome;
	}
	
	public void novoUsuario(MyObjectEvent s){
		Servidor serv = (Servidor) s.getSource();
		File file = serv.getFile();
		ObjectInputStream input;
		try {
			input = new ObjectInputStream(new FileInputStream(file));
			try {
				ArrayList<Usuario> clientes = (ArrayList<Usuario>)input.readObject();
				saida.writeObject(clientes);
			} catch (Exception e) {
				serv.removeSaidaListener(this);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		
//		ArrayList<Usuario> clientes = serv.getCliente();
//		saida.writeObject(clientes);
		
	}

}
